# import logging
# import os

# LOG_DIR = os.path.join(os.path.dirname(__file__), '../logs')
# LOG_PATH = os.path.join(LOG_DIR, 'duckdb_helper.log')

# if not os.path.exists(LOG_DIR):
#     os.makedirs(LOG_DIR)

# logging.basicConfig(
#     filename=LOG_PATH,
#     level=logging.INFO,
#     format='%(asctime)s %(levelname)s %(message)s',
#     datefmt='%Y-%m-%d %H:%M:%S',
#     encoding='utf-8'  # 关键参数
# )
import logging
from logging.handlers import RotatingFileHandler
import os

# 确保日志目录存在
log_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
os.makedirs(log_dir, exist_ok=True)

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
    handlers=[
        # 控制台输出
        logging.StreamHandler(),
        # 文件输出(按大小轮转)
        RotatingFileHandler(
            filename=os.path.join(log_dir, 'app.log'),
            maxBytes=10*1024*1024,  # 10MB
            backupCount=5,
            encoding='utf-8'
        )
    ]
)

# 获取logger实例
logger = logging.getLogger(__name__)